<!DOCTYPE html>
<html>

	<head lang="en">
		<title>首页</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="js/bootstrap/css/bootstrap.min.css">
		<script src="js/jquery/jquery.min.js"></script>
		<script src="js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="css/reset.css" />
		<link rel="stylesheet" href="css/strategyDetails.css" />
		<script src="js/plugins/jrender/jrender.min.js"></script>
		<script src="js/common.js"></script>
		<link rel="stylesheet" href="js/plugins/dialog2/dialog.css">
		<script src="js/plugins/dialog2/dialog.min.js"></script>

		<script>
			$(function () {
                var user = JSON.parse(sessionStorage.getItem('user'));
                var id = getParams().id;
                console.log(id);
                $.get("/strategyDetails/" + id,function (data) {
                    $(".detail").renderValues(data);

                });

				//----------------------------攻略收藏--------------------------------
                if(user){

                    $.get("/strategyCollection/get",{userId:user.id,strategyId:id},function (data) {

                        if(data.success){
                            $('#collectBtn').css('color',"blue");

                        }
                    })

                }
                //--------------------------------------------------------------
                $('#collectBtn').click(function () {

                    if(user){
                        $.get("/strategyCollection/get",{userId:user.id,strategyId:id},function (data) {

                            if(data.success){//表示已经收藏
                                $(document).dialog({
                                    type: 'confirm',
                                    content: '取消收藏?',
                                    position: 'bottom',  // center: 居中; bottom: 底部
                                    onClickConfirmBtn:function () {
                                        //删除操作
                                        $.post("/strategyCollection/delete",{userId:user.id,strategyId:id},function (data) {
                                            if (data.success){
                                                $('#collectBtn').css("color","gray");
                                                $(document).dialog({
                                                    type : 'notice',
                                                    infoText: '已取消收藏',
                                                    autoClose: 1500,
                                                    position: 'bottom'  // center: 居中; bottom: 底部
                                                });
                                            }
                                        })
                                    }
                                });

                            }else {

                                //已经登陆,将用户id及游记id存入数据库
                                $.post("/strategyCollection/save",{userId:user.id,strategyId:id},function (data) {
                                    if (data.success){
                                        //成功就改变样式
                                        $('#collectBtn').css('color',"blue");
                                        $(document).dialog({
                                            type : 'notice',
                                            infoText: '收藏成功',
                                            autoClose: 1500,
                                            position: 'bottom'  // center: 居中; bottom: 底部
                                        });

                                    }else {
                                        alert(data.msg);
                                    }
                                })
                            }
                        })

                    }else {
                        //没登陆先去登陆
                        $(document).dialog({
                            type: 'confirm',
                            content: '亲,请先登录',
                            position: 'bottom',  // center: 居中; bottom: 底部
                            onClickConfirmBtn:function () {
                                window.location.href="/login.html";
                            }
                        });
                    }
                })





            })
		</script>
	</head>

	<body>

	<div class=" nav-search">
		<a href="javascript:history.go(-1);">
			<span><i class="fa fa-chevron-left"></i></span>
		</a>
	</div>
	<hr>

	<div class="container detail">
		<h4 class="title"><strong render-html="title"></strong></h4>
		<img class="head-img" render-src="coverUrl">
		<div class="author" ><span ></span></div>
		<div class="content" render-html="strategyContent.content">

		</div>
		<div class="creatTime" render-html="createTime"><span ></span></div>
	</div>

	<hr>

	<div class="container d-flex">
		<div class="p-2  flex-fill">
			<i class="fa fa-thumbs-o-up"  id="likeBtn"> </i>
		</div>
		<div class="p-2  flex-fill"><i class="fa  fa-commenting-o"  id="commentBtn"> </i>
		</div>
		<div class="p-2  flex-fill"><i class="fa save fa-star-o " id="collectBtn"></i>
		</div>
	</div>
	</body>

</html>